//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "VanillaSwap.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/CashFlow.h>
#include <gen/QL/Times/Schedule.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instruments/Swap.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#define STRUCT
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (QL::Instruments::VanillaSwap::TypeEnum type, Double nominal, Cephei::QL::Times::ISchedule^ fixedSchedule, Double fixedRate, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Cephei::QL::Times::IDayCounter^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Cephei::QL::IPricingEngine^ QL_Pricer) : CSwap(CVanillaSwap::typeid)
{
    CSchedule^ _CfixedSchedule;
    CDayCounter^ _CfixedDayCount;
    CSchedule^ _CfloatSchedule;
    CIborIndex^ _CiborIndex;
    CDayCounter^ _CfloatingDayCount;
    try
    {
#ifdef HANDLE
        _phVanillaSwap = NULL;
#endif
        QuantLib::VanillaSwap::Type _type = (QuantLib::VanillaSwap::Type)type ;
        QuantLib::Real _nominal = (QuantLib::Real)ValueHelper::Convert (nominal); //d
        _CfixedSchedule = safe_cast<CSchedule^> (fixedSchedule);
        _CfixedSchedule->Lock();
        QuantLib::Schedule& _fixedSchedule = static_cast<QuantLib::Schedule&> (_CfixedSchedule->GetReference ()); 
        QuantLib::Rate _fixedRate = (QuantLib::Rate)ValueHelper::Convert (fixedRate); //d
        _CfixedDayCount = safe_cast<CDayCounter^> (fixedDayCount);
        _CfixedDayCount->Lock();
        QuantLib::DayCounter& _fixedDayCount = static_cast<QuantLib::DayCounter&> (_CfixedDayCount->GetReference ()); 
        _CfloatSchedule = safe_cast<CSchedule^> (floatSchedule);
        _CfloatSchedule->Lock();
        QuantLib::Schedule& _floatSchedule = static_cast<QuantLib::Schedule&> (_CfloatSchedule->GetReference ()); 
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Spread _spread = (QuantLib::Spread)ValueHelper::Convert (spread); //d
        _CfloatingDayCount = safe_cast<CDayCounter^> (floatingDayCount);
        _CfloatingDayCount->Lock();
        QuantLib::DayCounter& _floatingDayCount = static_cast<QuantLib::DayCounter&> (_CfloatingDayCount->GetReference ()); 
        boost::optional<QuantLib::BusinessDayConvention> _paymentConvention;
        if (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (paymentConvention))
        {
            QuantLib::BusinessDayConvention t = (QuantLib::BusinessDayConvention)paymentConvention->Value;
            _paymentConvention = boost::optional<QuantLib::BusinessDayConvention> (t);
        }
        else
            _paymentConvention = boost::none;
        _ppVanillaSwap = new boost::shared_ptr<QuantLib::VanillaSwap> (new QuantLib::VanillaSwap ( _type,  _nominal,  _fixedSchedule,  _fixedRate,  _fixedDayCount,  _floatSchedule,  _iborIndex,  _spread,  _floatingDayCount,  _paymentConvention ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppVanillaSwap)->setPricingEngine (_QL_Pricer);
        SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CfixedSchedule != nullptr) _CfixedSchedule->Unlock();
        if (_CfixedDayCount != nullptr) _CfixedDayCount->Unlock();
        if (_CfloatSchedule != nullptr) _CfloatSchedule->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CfloatingDayCount != nullptr) _CfloatingDayCount->Unlock();
    }
}
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (boost::shared_ptr<QuantLib::VanillaSwap>& childNative, Object^ owner) : CSwap(CVanillaSwap::typeid)
{
#ifdef HANDLE
	_phVanillaSwap = NULL;
#endif
	_ppVanillaSwap = &childNative;
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
}
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (QuantLib::VanillaSwap& childNative, Object^ owner) : CSwap(CVanillaSwap::typeid)
{
#ifdef HANDLE
	_phVanillaSwap = NULL;
#endif
	_ppVanillaSwap = new boost::shared_ptr<QuantLib::VanillaSwap> (&childNative);
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
    _VanillaSwapOwner = owner;
    _SwapOwner = owner;
}

Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (CVanillaSwap^ copy) : CSwap(CVanillaSwap::typeid)
{
#ifdef HANDLE
	_phVanillaSwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppVanillaSwap = new boost::shared_ptr<QuantLib::VanillaSwap> (copy->GetShared());
        _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
    }
}
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (PLATFORM::Type^ t) : CSwap(CVanillaSwap::typeid)
{
#ifdef HANDLE
	_phVanillaSwap = NULL;
#endif
	if (!t->IsSubclassOf(CVanillaSwap::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (QuantLib::Handle<QuantLib::VanillaSwap>& childNative, Object^ owner)  : CSwap(CVanillaSwap::typeid)
{
	_phVanillaSwap = &childNative;
	_ppVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::VanillaSwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
    _VanillaSwapOwner = owner;
}
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (QuantLib::Handle<QuantLib::VanillaSwap> childNative)  : CSwap(CVanillaSwap::typeid)
{
	_phVanillaSwap = &childNative;
	_ppVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::VanillaSwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CVanillaSwap::CVanillaSwap (QuantLib::VanillaSwap childNative)  : CSwap(CVanillaSwap::typeid)
{
#ifdef HANDLE
	_phVanillaSwap = NULL;
#endif
	_ppVanillaSwap = new boost::shared_ptr<QuantLib::VanillaSwap> (new QuantLib::VanillaSwap (childNative));
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppVanillaSwap));
}
#endif

Cephei::QL::Instruments::CVanillaSwap::~CVanillaSwap ()
{
    if (_ppVanillaSwap != NULL)
    {
	    delete _ppVanillaSwap;
        _ppVanillaSwap = NULL;
    }
}
Cephei::QL::Instruments::CVanillaSwap::!CVanillaSwap ()
{
    if (_ppVanillaSwap != NULL)
    {
	    delete _ppVanillaSwap;
    }
}
QuantLib::VanillaSwap& Cephei::QL::Instruments::CVanillaSwap::GetReference ()
{
    if (_ppVanillaSwap == NULL) throw REFNEW NativeNullException ();
	return **_ppVanillaSwap;
}
boost::shared_ptr<QuantLib::VanillaSwap>& Cephei::QL::Instruments::CVanillaSwap::GetShared ()
{
    if (_ppVanillaSwap == NULL) throw REFNEW NativeNullException ();
	return *_ppVanillaSwap;
}
QuantLib::VanillaSwap* Cephei::QL::Instruments::CVanillaSwap::GetPointer ()
{
    if (_ppVanillaSwap == NULL) throw REFNEW NativeNullException ();
	return &**_ppVanillaSwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::VanillaSwap>& Cephei::QL::Instruments::CVanillaSwap::GetHandle ()
{
	if (_phVanillaSwap == NULL)
	{
		_phVanillaSwap = new Handle<QuantLib::VanillaSwap> (*_ppVanillaSwap);
	}
	return *_phVanillaSwap;
}
#endif
bool Cephei::QL::Instruments::CVanillaSwap::HasNative () 
{
	return (_ppVanillaSwap != NULL);
}

Double Cephei::QL::Instruments::CVanillaSwap::FairRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppVanillaSwap)->fairRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FairSpread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppVanillaSwap)->fairSpread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Instruments::CVanillaSwap::FixedDayCount::get ()
{
    try
    {
    	QuantLib::DayCounter& _rv = (QuantLib::DayCounter&)(*_ppVanillaSwap)->fixedDayCount ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CVanillaSwap::FixedLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppVanillaSwap)->fixedLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FixedLegBPS::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppVanillaSwap)->fixedLegBPS ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FixedLegNPV::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppVanillaSwap)->fixedLegNPV ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FixedRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppVanillaSwap)->fixedRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Instruments::CVanillaSwap::FixedSchedule::get ()
{
    try
    {
    	QuantLib::Schedule& _rv = (QuantLib::Schedule&)(*_ppVanillaSwap)->fixedSchedule ( );   
        Cephei::QL::Times::CSchedule^ _nrv = REFNEW Cephei::QL::Times::CSchedule (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Instruments::CVanillaSwap::FloatingDayCount::get ()
{
    try
    {
    	QuantLib::DayCounter& _rv = (QuantLib::DayCounter&)(*_ppVanillaSwap)->floatingDayCount ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CVanillaSwap::FloatingLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppVanillaSwap)->floatingLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FloatingLegBPS::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppVanillaSwap)->floatingLegBPS ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::FloatingLegNPV::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppVanillaSwap)->floatingLegNPV ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Instruments::CVanillaSwap::FloatingSchedule::get ()
{
    try
    {
    	QuantLib::Schedule& _rv = (QuantLib::Schedule&)(*_ppVanillaSwap)->floatingSchedule ( );   
        Cephei::QL::Times::CSchedule^ _nrv = REFNEW Cephei::QL::Times::CSchedule (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IIborIndex^ Cephei::QL::Instruments::CVanillaSwap::IborIndex::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::IborIndex>& _rv = (boost::shared_ptr<QuantLib::IborIndex>&)(*_ppVanillaSwap)->iborIndex ( );   
        Cephei::QL::Indexes::CIborIndex^ _nrv = REFNEW Cephei::QL::Indexes::CIborIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::Nominal::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppVanillaSwap)->nominal ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Instruments::CVanillaSwap::PaymentConvention::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppVanillaSwap)->paymentConvention ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CVanillaSwap::Spread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppVanillaSwap)->spread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Instruments::VanillaSwap::TypeEnum Cephei::QL::Instruments::CVanillaSwap::Type::get ()
{
    try
    {
    	QuantLib::VanillaSwap::Type _rv = (QuantLib::VanillaSwap::Type)(*_ppVanillaSwap)->type ( );   
        QL::Instruments::VanillaSwap::TypeEnum _nrv = (QL::Instruments::VanillaSwap::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IVanillaSwap^ Cephei::QL::Instruments::CVanillaSwap_Factory::Create (QL::Instruments::VanillaSwap::TypeEnum type, Double nominal, Cephei::QL::Times::ISchedule^ fixedSchedule, Double fixedRate, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, Cephei::QL::Indexes::IIborIndex^ iborIndex, Double spread, Cephei::QL::Times::IDayCounter^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CVanillaSwap ( type,  nominal,  fixedSchedule,  fixedRate,  fixedDayCount,  floatSchedule,  iborIndex,  spread,  floatingDayCount,  paymentConvention,  QL_Pricer);
}
